package com.guijq.graphqldemo.resolver;

import com.coxautodev.graphql.tools.GraphQLResolver;
import com.guijq.graphqldemo.dao.AuthorRepository;
import com.guijq.graphqldemo.dao.entity.Author;
import com.guijq.graphqldemo.dao.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yangjf
 * @version 0.1.0
 * @time 2018/9/19/019
 */
@Component
public class BookResolver implements GraphQLResolver<Book> /* This class is a resolver for the Book "Data Class" */ {

    @Autowired
    private AuthorRepository authorRepository;

    public Author author(Book book) {
        return authorRepository.findById(book.getAuthorId()).get();
    }
}